
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title>超市账单管理系统</title>
    <link rel="stylesheet" href="/statics/css/public.css"/>
    <link rel="stylesheet" href="/statics/css/style.css"/>
    <script type="text/javascript" src="/statics/js/jquery.js"></script>
    <script type="text/javascript">
        $(function () {
            //加载用户角色
            $.get("/sys/role/queryAll",function (result) {
                $.each(result,function (index,d) {
                    $("select[name='userRole']").append("<option value='"+d.id+"'>"+d.roleName+"</option>")
                });
                //选中
                var userRole=$("#userRole").val();
                $("select[name='userRole']").val(userRole);
            });
            $("#updateButton").click(function () {
                //表单验证
                //获取表单数据
                var data=$("form").serialize();
                //ajax请求
                $.post("/sys/user/update",data,function (result) {
                   if(result=='success'){
                       alert("修改成功！");
                       location.href="/sys/user/toList";
                   }else if(result=='error'){
                       alert("修改失败！");
                   }else{
                       alert("登录失效，请重新登录");
                   }
                });
            });
        })
    </script>
</head>
<body>
<section class="publicMian ">
    <div class="right">
        <div class="location">
            <strong>你现在所在的位置是:</strong>
            <span>用户管理页面 >> 用户修改页面</span>
        </div>
        <div class="providerAdd">
            <form >
                <!--div的class 为error是验证错误，ok是验证成功-->
                <div>
                    <label for="userName">用户名称：</label>
                    <input type="text" name="userName" id="userName" value="${user.userName}"/>
                    <input type="hidden" name="id" value="${user.id}">
                    <span >*</span>
                </div>

                <div>
                    <label >用户性别：</label>

                    <select name="gender">
                        <c:if test="${user.gender==1}">
                            <option value="2">男</option>
                            <option value="1" selected>女</option>
                        </c:if>
                        <c:if test="${user.gender==2}">
                            <option value="2" selected>男</option>
                            <option value="1" >女</option>
                        </c:if>
                    </select>
                </div>
                <div>
                    <label for="data">出生日期：</label>
                    <input type="data" name="birthday" id="data"
                           value="<fmt:formatDate value="${user.birthday}" pattern="yyyy-MM-dd"/>"/>
                    <span >*</span>
                </div>
                <div>
                    <label for="phone">用户电话：</label>
                    <input type="text" name="phone" id="phone" value="${user.phone}"/>
                    <span >*</span>
                </div>
                <div>
                    <label for="address">用户地址：</label>
                    <input type="text" name="address" id="address" value="${user.address}"/>
                </div>
                <div>
                    <label >用户角色：</label>
                    <select name="userRole"></select>
                    <input type="hidden" id="userRole" value="${user.role.id}">

                </div>
                <div class="providerAddBtn">
                    <!--<a href="#">保存</a>-->
                    <!--<a href="userList.html">返回</a>-->
                    <input type="button" value="保存" id="updateButton"/>
                    <input type="button" value="返回" onclick="history.back(-1)"/>
                </div>
            </form>
        </div>

    </div>
</section>
</body>
</html>
